<template>
  <div class="app-container">
    <el-form class="base-search-form" :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch">
      <el-form-item label="机构代码" prop="organCode">
        <el-input
          v-model="queryParams.organCode"
          placeholder="请输入机构代码"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="卡IIN" prop="cardIin">
        <el-input
          v-model="queryParams.cardIin"
          placeholder="请输入卡IIN"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    
    <div class="base-container mb-50px">
      <el-row :gutter="10" class="mb-10px">
        <!-- <el-col :span="1.5">
          <el-button
            type="primary"
            plain
            icon="Plus"
            @click="handleAdd"
            v-hasPermi="['bus:organwhitelist:add']"
          >新增</el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button
            type="warning"
            plain
            icon="Download"
            @click="handleExport"
            v-hasPermi="['bus:organwhitelist:export']"
          >导出</el-button>
        </el-col> -->
        <!-- <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar> -->
      </el-row>

      <el-table border v-loading="loading" :data="organwhitelistList">
        <el-table-column label="机构代码" align="center" prop="organCode" />
        <el-table-column label="卡IIN" align="center" prop="cardIin" />
        <!-- <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
          <template #default="scope">
            <el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)" v-hasPermi="['bus:organwhitelist:edit']">修改</el-button>
            <el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)" v-hasPermi="['bus:organwhitelist:remove']">删除</el-button>
          </template>
        </el-table-column> -->
      </el-table>
    </div>
    
    <pagination
      v-show="total>0"
      :total="total"
      v-model:page="queryParams.pageNum"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改机构白名单对话框 -->
    <Dialog v-model="showDialog" :title="dialogTitle">
      <edit-view
        ref="editView"
        @cancel="cancel"
        @confirm="confirm"      
      />
    </Dialog>
  </div>
</template>

<script setup name="Organwhitelist">
import { listOrganwhitelist, delOrganwhitelist } from "@/api/bus/organwhitelist"
import { nextTick } from "vue"
import EditView from './edit.vue'

const { proxy } = getCurrentInstance()
const editView = ref()

const organwhitelistList = ref([])
const loading = ref(true)
const showSearch = ref(true)
const ids = ref([])
const single = ref(true)
const multiple = ref(true)
const total = ref(0)
const showDialog = ref(false)
const dialogTitle = ref('')

const data = reactive({
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    organCode: null,
    cardIin: null
  }
})

const { queryParams } = toRefs(data)

/** 查询机构白名单列表 */
function getList() {
  loading.value = true
  listOrganwhitelist(queryParams.value).then(response => {
    organwhitelistList.value = response.rows
    total.value = response.total
    loading.value = false
  })
}

// 取消按钮
function cancel() {
  showDialog.value = false
}

function confirm() {
  cancel()
  getList()
}

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1
  getList()
}

/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm("queryRef")
  handleQuery()
}

// 多选框选中数据
function handleSelectionChange(selection) {
  ids.value = selection.map(item => item.id)
  single.value = selection.length != 1
  multiple.value = !selection.length
}

/** 新增按钮操作 */
function handleAdd() {
  showDialog.value = true
  dialogTitle.value = '添加机构白名单'
}

/** 修改按钮操作 */
function handleUpdate(row) {
  const _id = row.id || ids.value
  showDialog.value = true
  dialogTitle.value = '修改机构白名单'
  nextTick(() => {
    editView.value.pageInit(_id)
  })
}

/** 删除按钮操作 */
function handleDelete(row) {
  const _ids = row.id || ids.value
  proxy.$modal.confirm('是否确认删除该机构白名单').then(function() {
    return delOrganwhitelist(_ids)
  }).then(() => {
    getList()
    proxy.$modal.msgSuccess("删除成功")
  }).catch(() => {})
}

/** 导出按钮操作 */
function handleExport() {
  proxy.download('bus/organwhitelist/export', {
    ...queryParams.value
  }, `organwhitelist_${new Date().getTime()}.xlsx`)
}

getList()
</script>
